-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing Mysqld.normalizedSchema()
by formally parsing the query
#13866
Fixing Mysqld.normalizedSchema()
by formally parsing the query
#13866
Conversation
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
There's a few other places where we use string replacements, but where really parsing should be used: vitess/go/vt/mysqlctl/schema.go Lines 90 to 102 in b65cde1
vitess/go/vt/mysqlctl/schema.go Lines 438 to 445 in b65cde1
vitess/go/vt/mysqlctl/tmutils/schema.go Lines 213 to 234 in b65cde1
vitess/go/vt/wrangler/schema.go Lines 283 to 315 in b65cde1
|
…'UnqualifyDatabaseNamePlaceholder()'. A bit of all-round refactoring. Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…ema to translate into qualified schema Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@dbussink I don't think vitess/go/vt/wrangler/schema.go Lines 283 to 315 in b65cde1
text/template , haven't seen this elsewhere in vitess code), and not part of {{.DatabaseName}} thing.
|
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@dbussink After an hour of debugging a test failure, I came full circle to recognize that vitess/go/vt/wrangler/schema.go Lines 283 to 315 in b65cde1
|
Ah yes, the syntax of |
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
OK, good to go! Looking for reviews. Formatting is back to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except for the one question about a comment.
go/vt/sqlparser/utils.go
Outdated
@@ -118,6 +118,7 @@ func NormalizeAlphabetically(query string) (normalized string, err error) { | |||
// replaces any cases of the provided database name with the | |||
// specified replacement name. | |||
// Note: both database names provided should be unescaped strings. | |||
// The returned query is formatted canonically (will look different than original query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment still valid? Since you reverted the call to CanonicalString
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Signed-off-by: Matt Lord <mattalord@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I only had a minor comment and will let you resolve that as you feel best.
go/vt/mysqlctl/schema.go
Outdated
@@ -249,6 +250,27 @@ func (mysqld *Mysqld) collectSchema(ctx context.Context, dbName, tableName, tabl | |||
return fields, columns, schema, nil | |||
} | |||
|
|||
// normalizedStatement returns a table schema with database names replaced, and auto_increment annotations removed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment doesn't match the behavior, does it? We only do that replacement for views AFAICT. Which one is correct, the comment or the code? I think it's the comment as the code was just moved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
case *CreateDatabase: | ||
if node.DBName.String() == oldQualifier.String() { | ||
node.DBName = newQualifier | ||
cursor.Replace(node) | ||
modified = true | ||
} | ||
case *AlterDatabase: | ||
if node.DBName.String() == oldQualifier.String() { | ||
node.DBName = newQualifier | ||
cursor.Replace(node) | ||
modified = true | ||
} | ||
case *DropDatabase: | ||
if node.DBName.String() == oldQualifier.String() { | ||
node.DBName = newQualifier | ||
cursor.Replace(node) | ||
modified = true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to consolidate these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - golang
will give compilation errors, because SQLNode
(the shared interface for all these types) does not have a DBName
field (obviously as it is an interface, and each implementing type adds the fields independently).
in: "CREATE TABLE t (id int primary key)", | ||
out: "CREATE TABLE t (id int primary key)", | ||
}, | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is escaped but not qualified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow?
…cement Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Temporarily converted to draft because I want to confirm something before merging, and I don't want anyone else to accidentally merge in the interim. Will likely merge this shortly. |
This PR is being marked as stale because it has been open for 30 days with no activity. To rectify, you may do any of the following:
If no action is taken within 7 days, this PR will be closed. |
This PR was closed because it has been stale for 7 days with no activity. |
This PR is being marked as stale because it has been open for 30 days with no activity. To rectify, you may do any of the following:
If no action is taken within 7 days, this PR will be closed. |
This PR is being marked as stale because it has been open for 30 days with no activity. To rectify, you may do any of the following:
If no action is taken within 7 days, this PR will be closed. |
This PR was closed because it has been stale for 7 days with no activity. |
Description
This fixes #13865. The existing query editing mechanism is a naive string search & replace, which can lead to incorrect replacement of table names. This PR will work to formally parse the query and only replace DB names.
This will be done in stages. First, we introduce unit testing to support the existing behavior. Then, introduce unit tests that break with #13865. Last, we will introduce formal parsing that passes all tests.
Related Issue(s)
Fixes #13865
Checklist
Deployment Notes